package day9zy.zixun;

import java.net.*;
import java.util.Scanner;
import java.io.*;

public class ZixunClient {
    private String remoteHost = "192.168.100.207";
    private int remotePort = 8000;
    private DatagramSocket socket;

    public ZixunClient() throws IOException {
        socket = new DatagramSocket();
    }

    public static void main(String args[]) throws IOException {
        new ZixunClient().talk();
    }

    public void talk() throws IOException {
        try {
            //InetAddress[] allByName = InetAddress.getAllByName();
            InetAddress remoteIP = InetAddress.getByName(remoteHost);

            Scanner sc=new Scanner(System.in);
            System.out.print("请选择服务项：");
            String msg = null;
            while ((msg = sc.nextLine()) != null) {
                byte[] outputData = msg.getBytes();
                DatagramPacket outputPacket = new DatagramPacket(outputData,
                        outputData.length, remoteIP, remotePort);
                socket.send(outputPacket); //

                DatagramPacket inputPacket = new DatagramPacket(new byte[512],
                        512);
                socket.receive(inputPacket);
                System.out.println(new String(inputPacket.getData(), 0,
                        inputPacket.getLength()));
                switch (msg) {
                    case "物流": {
                        System.out.println("申通快递");
                        break;
                    }
                    case "退货": {
                        System.out.println("七天无理由退货");
                    }
                    case "退出": {
                        return;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            socket.close();
        }
    }
}


//        break;
//        }
//        }